package 代码记录.指定公司代码练习记录.华为_2024.分值100.第36start;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

/**
 * @author zx
 * @create 2024-02-16 13:11
 * 看懂人家的代码了，不难，二刷要自己能做出来
 */
public class 英文输入法_45 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String value = sc.nextLine();
        String str = sc.nextLine();
        solve(value, str);
    }

    public static void solve(String value, String targetStr) {
        if (value == null || value.length() == 0) {
            System.out.println("input error");
            return;
        }
        List<String> list = new ArrayList<>();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < value.length();i++) {
            char ch = value.charAt(i);
            if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) {
                sb.append(ch);
            } else {
                list.add(sb.toString());
                sb = new StringBuilder();
            }
        }
        List<String> resList = new ArrayList<>();
        for (int i = 0; i < list.size();i++) {
            //遍历list容器中的元素,并筛选出以指定字符串targetStr开头的元素
            if (list.get(i).startsWith(targetStr)) {
                resList.add(list.get(i));
            }
        }
        //排序(这样排序就按照字典序排好序了)
        Collections.sort(resList);
        //输出
        if (resList.size() > 0) {
            for (int j = 0; j < resList.size(); ++j) {
                String reslut = resList.get(j) + " ";
                System.out.print(reslut);
            }
            System.out.println();
        } else {
            System.out.println(targetStr);
        }
    }
}
